package util

import (
	"fmt"
	"go-toy/constant/response"
)

func echoPanic(err error, code int) {
	errPrefix := response.ResponseCode2Msg(code)
	errMsg := errPrefix
	if err.Error() != "" {
		errMsg = fmt.Sprintf("%s: %s", errMsg, err.Error())
	}
	panic(Response.ResponseBody(code, errMsg, nil))
}

func SimplePanic(err error) {
	code := response.CODE_SERVER_ERROR
	echoPanic(err, code)
}

func ServicePanic(err error) {
	code := response.CODE_SERVICE_ERROR
	echoPanic(err, code)
}

func UtilPanic(err error) {
	code := response.CODE_UTIL_ERROR
	echoPanic(err, code)
}
